// Raf Lempens & Bjorn Schobben
#include "World.h"
#include "GameBehavior.h"

World::World(): board(0)
{
}


World::~World()
{
	Clear();
}

void World::Clear()
{
	if (board)
	{
		delete board;
	}

	// clear objects here
}

void World::AddObject(GameObject* object)
{
	objects.push_back(object);

	board->Update(object);
}

void World::Simulate()
{
	std::list<GameObject*>::iterator it;

	if (!board)
		return;

	for(it = objects.begin(); it != objects.end(); ++it)
	{
		GameObject* object = (*it);
		GameBehavior* behavior = object->GetBehavior();

		// HIER MOET DE FABRIEKSOBJECTEN ALS LAATSTE GEACTIVEERD WORDEN
		// DUS... BEHAVIOR PRIORITEITEN IEMAND?

		if (behavior)
		{
			BeginBehaviorSimulation();

			behavior->GenerateSteps(*board);
			behavior->Execute();

			EndBehaviorSimulation();
		}

		object->BehaviorFinished();
	}
}

void World::BeginBehaviorSimulation()
{
}

void World::EndBehaviorSimulation()
{
}


void World::Resize(unsigned int width, unsigned int height)
{
	if (!board)
	{
		board = CreateBoard();
	}

	board->Resize(width, height);
}


Board* World::CreateBoard()
{
	return new Board();
}
